﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace fess.Graphics
{
  class SpriteSheet
  {
    Texture2D sheet;
    Point spriteSize;
    Vector2 origin;
    float sourceRotation;

    public SpriteSheet(Texture2D sheet, Point spriteSize, Vector2 origin, float rotation = 0)
    {
      this.sheet = sheet;
      this.spriteSize = spriteSize;
      this.origin = origin;
      this.sourceRotation = rotation;
    }

    public int Width { get { return sheet.Width / spriteSize.X; } }
    public int Height { get { return sheet.Height / spriteSize.Y; } }

    public void Draw(SpriteBatch batch, int x, int y, Vector2 place, Rectangle view, float rotation, float depth, float scale, Color color)
    {
      batch.Draw(sheet, new Vector2((int)(place.X - view.X), (int)(place.Y - view.Y)),
        new Rectangle(spriteSize.X * x, spriteSize.Y * y, spriteSize.Y, spriteSize.X),
        color, rotation + sourceRotation, origin, scale, SpriteEffects.None, depth);
    }

    public Texture2D Texture { get { return sheet; } }
    public Point SpriteSize { get { return spriteSize; } }
  }

  class CharacterMovementSheet : SpriteSheet
  {
    public CharacterMovementSheet(Texture2D sheet)
      : base(sheet, new Point(32, 32), new Vector2(16, 22))
    {
    }
  }
}
